<template>
  <el-header>
    <div class="left">
      <el-icon
        @click="handleCollapse"
        :style="{
          transform: `rotate(${$store.state.isCollapsed ? '-180deg' : '0'})`,
          transition: 'all 0.5s',
        }"
        ><Menu
      /></el-icon>
      <span>企业门户网站管理系统</span>
    </div>
    <div class="right">
      <span>欢迎回来！</span>
      <el-dropdown trigger="click">
        <el-icon><Avatar /></el-icon>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleGoCenter"
              >个人中心</el-dropdown-item
            >
            <el-dropdown-item @click="handleLogOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { useStore } from "vuex";
import { useRouter } from "vue-router";

const store = useStore();
const router = useRouter();
const handleCollapse = () => {
  store.commit("changeCollapse");
};

const handleGoCenter = () => {
  router.push({
    path: "/center",
  });
};

const handleLogOut = () => {
  localStorage.removeItem("node-vue3-token");
  router.push({
    path: "/login",
  });
};
</script>

<style lang="scss" scoped>
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #091b41;
  color: #fff;
}
.left,
.right {
  display: flex;
  align-items: center;
}
.el-icon {
  cursor: pointer;
  font-size: 20px;
  margin-right: 20px;
  color: #fff;
}
</style>
